package com.chenfwind.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.chenfwind.common.ResultVO;
import com.chenfwind.domain.Trajectory;
import com.chenfwind.domain.vo.TrajectoryVO;
import com.chenfwind.service.TrajectoryService;

/****
 * 轨迹Controller
 * 
 * @author Swinglife
 * 
 */
@Controller
@RequestMapping("/tra")
public class TrajectoryController {
	
	@Autowired
	private TrajectoryService trajectoryService;
	
	@ResponseBody
	@RequestMapping(value = "/getTraByBook" , method = RequestMethod.POST)
	public ResultVO<List<TrajectoryVO>> getTraByBook(HttpSession session,@RequestParam(value = "bookId" ,required = false) String bookId){
		ResultVO<List<TrajectoryVO>> vo = ResultVO.create();
		List<TrajectoryVO> traVOList = new ArrayList<TrajectoryVO>();
		List<Trajectory> traList =trajectoryService.getAllTrajectoryByBook(bookId);
		for (Trajectory tra : traList){
			traVOList.add(Tra2TraVO(tra , null));
		}
		vo.setResult(traVOList);
		vo.reCalcStatus();
		return vo;
	}
	
	public TrajectoryVO Tra2TraVO(Trajectory tra ,TrajectoryVO traVO){
		if (traVO == null) {
			traVO = new TrajectoryVO();
			traVO.setId(tra.getId());
		}
		com.chenfwind.utils.BeanUtils.copyProperties(tra, traVO);
		return traVO;
	}
}
